class InfoController < ApplicationController
  
  def method_missing(name, *args) 
    render :template=>"index/null"
  end
  
  def index
    redirect_to :action=>"info"
  end
  
  
  def info 
    if @user = User.find_by_id(@activeuser.user_id) and not @activeuser.guest?
      @incumbents = @user.incumbents
      @friends = @user.friends
      @inbox_messages = @user.inbox_messages
      @outbox_messages = @user.outbox_messages
      @reports = @user.reports
    else
      remove_session
      flash[:notice]=["请登陆网站!"]
      redirect_to :controller=>'login',:action=> 'login'
    end
  end
  
  def upload_picture
    # object=0 user
    @id=params[:id]
    @object=params[:object]
    render :layout=>false
  end
  
  def save_picture
    obj_id=params[:object].to_i
    if request.post?
      if picture=@activeuser.create_picture(params[:picture],obj_id)
        @activeuser.delete_picture(params[:id])
        flash[:notice]="<li>图片上传成功。</li>"
        redirect_to :controller=>"info",:action=>"upload_picture",:id=>picture.id, :object=>obj_id
      else
        flash[:notice]="<li>图片格式不符，上传失败。</li>"
        redirect_to :controller=>"info",:action=>"upload_picture",:id=>id, :object=>obj_id
      end
    end
  rescue  
    flash[:notice]="<li>图片格式不符，上传失败。</li>"
    redirect_to :controller=>"info",:action=>"upload_picture",:id=>id, :object=>obj_id
  end
end
